<template>
  <div class="app-container">

    <!--查看-->
    <div class="editdata">
      <p class="back"><span class="el-icon-arrow-left">运营</span> / <span>操作指南</span></p>
      <el-form ref="form"
               :model="viewForm"
               :rules="rules"
               label-width="80px">
        <div>
          <el-row>
            <el-col :span="6"
                    style="border: 1px solid blue">
              <div class="editbox">
                <el-form-item label="新增章节">
                </el-form-item>
              </div>
            </el-col>

            <el-col :span="16"
                    style="margin-left: 10px">
              <div class="editbox">
                <el-form-item label="详细内容">
                  <editor api-key="4ed6kvrs1pq3f86i1z9bau4jjbrbr71e642vkzjty2zqxiqd"
                          v-model="viewForm.messageContent"
                          :min-height="500" />
                </el-form-item>
              </div>

            </el-col>
          </el-row>
        </div>
        <div style="width: 100%;border-bottom: 1px solid #979797">
        </div>
      </el-form>
      <div slot="footer"
           class="dialog-footer"
           style="float: right">
        <el-button style="background-color: #aa2290;color: white"
                   type="primary"
                   @click="handleReply1">删 除</el-button>
        <el-button @click="handleEnd1">保 存</el-button>
      </div>
    </div>

  </div>
</template>

<script>
import { listMessage, getMessage, delMessage, addMessage, updateMessage, replyMessage, endMessage, downloadMessageFile } from "@/api/operate/message";
import DragUpload from "@/components/DragUpload";


export default {
  components: {
    DragUpload,
  },

  name: "Message",
  dicts: ['sys_message_status', 'sys_message_type'],
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 留言表格数据
      messageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      isView: false,//是否查看页面
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        messageTitle: undefined,
        createBy: undefined,
        messageStatus: undefined
      },
      // 表单参数
      form: {
        file: {}
      },

      replyForm: {
        file: {}
      },

      viewForm: {

      },

      // 弹出层标题
      replyTitle: "",
      // 是否显示弹出层
      replyOpen: false,

      // 表单校验
      rules: {
        messageTitle: [
          { required: true, message: "留言标题不能为空", trigger: "blur" }
        ]
      },

      replyRules: {
        messageContent: [
          { required: true, message: "回复内容不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created () {
    this.getList();
  },
  methods: {
    goBack () {
      this.open = false
      this.isView = false
    },
    replyReset () {
      this.replyForm = {
        messageId: undefined,
        replyContent: undefined,
      };
      this.resetForm("replyForm");
      this.replyOpen = false
      this.replyTitle = "回复"
    },

    handleEnd1 () {
      const id = this.replyForm.messageId;
      var that = this;
      this.$modal.confirm('当前留言内容确定结束，可以关闭留言了么？').then(function () {
        return endMessage(id + "");
      }).then(() => {
        this.$modal.msgSuccess("结束成功");
        that.open = false;
        that.isView = false;
        this.getList();
      }).catch(() => { });
    },

    /**回复按钮*/
    handleReply1 () {
      this.replyOpen = true;
      this.replyTitle = "回复";
    },

    /** 查看按钮 */
    handleView (row) {
      this.reset();
      const id = row.id || this.ids
      this.replyForm.messageId = id;
      getMessage(id).then(response => {
        this.viewForm = response.data;
        this.isView = true;
        this.title = "查看留言";
      });
    },

    //回复确定按钮
    replySubmitForm: function () {
      if (this.replyForm.messageId != undefined) {
        replyMessage(this.replyForm).then(response => {
          this.$modal.msgSuccess("回复成功");
          this.replyOpen = false;
          this.getList();
        });
      }
    },

    downloadMessageFile (url, fileName) {
      downloadMessageFile(url, fileName);
    },

    //回复取消按钮
    replyCancel () {
      this.replyOpen = false
    },


    /** 查询留言列表 */
    getList () {
      this.loading = true;
      listMessage(this.queryParams).then(response => {
        this.messageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.isView = false
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        id: undefined,
        messageTitle: undefined,
        messageType: undefined,
        messageContent: undefined,
        messageStatus: "1",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },

    /**回复按钮*/
    handleReply (row) {
      this.replyReset();
      const id = row.id || this.replyForm.messageId
      this.replyForm.messageId = id;
      this.replyOpen = true;
      this.replyTitle = "回复";
    },

    /** 新增按钮操作 */
    handleAdd () {
      this.reset();
      this.open = true;
      this.isView = false
      this.title = "添加留言";
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.reset();
      const id = row.id || this.ids
      getMessage(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.isView = false
        this.title = "修改留言";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateMessage(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.isView = false
              this.getList();
            });
          } else {
            addMessage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.isView = false
              this.getList();
            });
          }
        }
      });
    },

    /** 删除按钮操作 */
    handleDelete (row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除留言编号为"' + ids + '"的数据项？').then(function () {
        return delMessage(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },

    /** 结束按钮操作 */
    handleEnd (row) {
      const id = row.id || this.ids
      this.$modal.confirm('当前留言内容确定结束，可以关闭留言了么？').then(function () {
        return endMessage(id + "");
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("结束成功");
      }).catch(() => { });
    }
  }
};
</script>

<style lang="scss" scoped>
.app-container {
  padding: 0;
  .body {
    padding: 20px;
  }
  .editdata {
    width: 100%;
    //height: 89vh;
    background: #f2f3f4;
    border-radius: 0px 0px 0px 0px;
    padding: 1px 20px;
    box-sizing: border-box;
    // 面包屑样式
    .back {
      .el-icon-arrow-left {
        color: #979797;
        cursor: pointer;
      }
      span {
        font-size: 14px;
        font-family: Source Code Pro-Regular, Source Code Pro;
        font-weight: 400;
        color: #1f2329;
        line-height: 22px;
      }
    }
    // form表单样式
    .editbox {
      background: #ffffff;
      padding: 20px;
      box-sizing: border-box;
      background: #ffffff;
      box-shadow: 0px 4px 12px 0px rgba(211, 211, 211, 0.25);
      border-radius: 6px 6px 6px 6px;
    }
    .editfooter {
      margin-top: 20px;
      > div {
        display: flex;
        padding-bottom: 44px;
        .footbox {
          width: 150px;
          height: 96px;
          background: #f7f8fa;
          border-radius: 4px 4px 4px 4px;
          display: flex;
          justify-content: center;
          align-items: center;
          margin-right: 20px;
          position: relative;
          cursor: pointer;
          img {
            width: 23px;
            height: 24px;
          }
          .icon_box {
            width: 16px;
            height: 16px;
            position: absolute;
            right: 10px;
            top: 10px;
          }
        }
      }
    }

    h3 {
      font-family: Source Code Pro-Bold, Source Code Pro;
      font-weight: bold;
      color: #1f2329;
      line-height: 24px;
      margin: 0 0 20px 0;
      padding: 0;
    }
  }

  // 取消保存审核公用样式----后有需要 可差离出去
  .btn {
    display: inline-block;
    width: 80px;
    height: 40px;
    text-align: center;
    line-height: 40px;
    margin-right: 20px;
    cursor: pointer;
  }
  .cancel {
    background: #e6ebf0;
    border-radius: 2px 2px 2px 2px;
  }
  .save {
    background: #0b9eae;
    color: #ffffff;
    border-radius: 2px 2px 2px 2px;
  }
  .examine {
    width: 161px;
    background: #aa2290;
    color: #ffffff;
    border-radius: 4px 4px 4px 4px;
  }
}
</style>
